import React, { useEffect, useState } from "react";
import Add from "../components/student/Add";
import Update from "../components/student/Update";
import Search from "../components/student/Search";
import List from "../components/student/List";
import { getAll } from "../services/student";
export default function Student() {
    let [students, setStudents] = useState([]);
    let [student, setStudent] = useState({ name: "", age: 0, gender: "" });
    let [searchObj, setSearchObj] = useState({});
    let [updateVisible, setUpdateVisible] = useState(false);

    const show = async (params) => {
        if (params) {
            setSearchObj(params);
        } else {
            params = searchObj;
        }
        let data = await getAll(params);
        setStudents(data.data.rows);
    };
    return (
        <div>
            <Add show={show} />
            <Update
                show={show}
                student={student}
                setStudent={setStudent}
                updateVisible={updateVisible}
            />
            <Search show={show} />
            <List
                show={show}
                students={students}
                setStudent={setStudent}
                setUpdateVisible={setUpdateVisible}
            />
        </div>
    );
}
